from rest_framework.response import Response


# 重写jwt返回结果方法

def jwt_response_payload_handler(token,user,request):

    return  {
        'token':token,
        'username':user.username,
        'id':user.id,
    }



from rest_framework.pagination import PageNumberPagination

class PageNum(PageNumberPagination):
    """
    自定义分页器
    """
    page_size_query_param = 'pagesize' #指定每页展示数量的参数
    max_page_size = 10      #每页最多返回量
    def get_paginated_response(self, data):
        #     return Response(OrderedDict([
        #         ('count', self.page.paginator.count),
        #         ('next', self.get_next_link()),
        #         ('previous', self.get_previous_link()),
        #         ('results', data)
        #     ]))
        return Response({
            'count':self.page.paginator.count,
            'lists':data,
            'page':self.page.number, #页码
            'pages':self.page.paginator.num_pages, #总页数
            'pagesize':self.max_page_size #页容量

        })
